// 链接数据库
const mysql = require('mysql');
class DButils {
    getConn(){
        let conn = mysql.createConnection({
            host:"127.0.0.1",
            port:3306,
            user:'root',
            password:'123456',
            database:'campus',
            multipleStatements:true //开启之后，可以多条sql语句同时执行
        })
        return conn;
    }
    excuteSql(strSql,params=[]){
        let p = new Promise((resolve,reject) => {
            let conn = this.getConn();
            conn.query(strSql,params,(error,results) => {
                if(error){
                    reject(error);
                }else{
                    resolve(results);
                }
                conn.end();
            })
        })
        return p;
    }
}

module.exports = DButils;